import 'package:flutter/material.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';
import '../../models/order_detail_model.dart';

typedef GoPayCallback = void Function();

class DetailTopView extends StatelessWidget {
  final DetailInfoModel model;
  final GoPayCallback onGoPay;
  final AppLocalizations localizations;

  const DetailTopView({
    super.key,
    required this.model,
    required this.onGoPay,
    required this.localizations,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 15,vertical: 15),
      padding: const EdgeInsets.only(top: 15, left: 15, right: 15, bottom: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(15),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Image.asset(
                'assets/images/statue1.png',
                width: 20,
                height: 20,
              ),
              const SizedBox(width: 8),
              SizedBox(
                width: 120,
                child: Text(
                  _getStatusText(model.status),
                  style: const TextStyle(
                    fontSize: 15,
                    color: Color(0xFF333333),
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              const Spacer(),
              if (model.status == 0)
                ElevatedButton(
                  onPressed: onGoPay,
                  style: ElevatedButton.styleFrom(
                    backgroundColor: Color(0xFF5D5FEE),
                    padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
                    minimumSize: const Size(0, 28),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(15),
                    ),
                  ),
                  child: Text(
                    AppLocalizations.of(context)!.goPay,
                    style: const TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.bold,
                      color: Colors.white,
                    ),
                  ),
                ),
            ],
          ),
          SizedBox(height: 10),
          Text(
            _getDescriptionText(model),
            style: const TextStyle(
              fontSize: 13,
              color: Color(0xFF7B7B7B),
            ),
          ),
        ],
      ),
    );
  }

  String _getStatusText(double status) {
    switch (status) {
      case 0:
        return localizations.pendingPayment;
      case 1:
        return localizations.pendingShipment;
      case 2:
        return localizations.pendingReceipt;
      case 3:
        return localizations.completed;
      case 4:
        return localizations.canceled;
      case 5:
        return localizations.closed;
      case 6:
        return localizations.afterSales;
      case 7:
        return localizations.afterCompleted;
      case 8:
      case 9:
        return localizations.completed;
      default:
        return '';
    }
  }

  String _getDescriptionText(DetailInfoModel model) {
    switch (model.status) {
      case 0:
        return '${localizations.paymentDue}：${model.symbol}${model.paymentAmount}${localizations.completeWithin12Hours}';
      case 1:
        return localizations.paymentSuccessfulCustomerServiceIsProcessingYourOrder;
      case 2:
        return '';
      case 3:
      case 8:
      case 9:
        return '${localizations.order}${localizations.completed}';
      case 4:
        return '';
      case 5:
        return model.closeType;
      case 6:
        return localizations.afterSalesProcessing;
      case 7:
        return localizations.bankRefundProcessing;
      default:
        return '';
    }
  }
}